home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.image.FilteredImageSource;
- import java.awt.image.ImageProducer;
- import java.net.URL;
-
- public class ImageButton extends Applet implements Runnable {
- Thread workThread;
- private Image button_up;
- private Image button_down;
- private Image button_faded;
- private AudioClip sound;
- private String url;
- private String status;
- private String target;
- private boolean isup;
- private boolean isdown;
- private boolean animate;
- private int width;
- private int height;
- private int border;
- private int frame;
- MediaTracker tracker;
-
- public void stop() {
- if (this.workThread != null) {
- this.workThread.stop();
- }
-
- }
-
- public boolean mouseEnter(Event var1, int var2, int var3) {
- ((Applet)this).showStatus(this.status);
- this.isup = true;
- ((Component)this).repaint();
- return true;
- }
-
- public boolean mouseExit(Event var1, int var2, int var3) {
- ((Applet)this).showStatus("");
- this.isup = false;
- this.isdown = false;
- ((Component)this).repaint();
- return true;
- }
-
- public void paint(Graphics var1) {
- if (this.isup) {
- if (this.frame == 0) {
- var1.drawImage(this.button_up, 0, 0, this);
- if (this.animate) {
- this.frame = 1;
- }
- } else {
- var1.drawImage(this.button_down, 0, 0, this);
- this.frame = 0;
- }
-
- for(int var3 = 0; var3 < this.border; ++var3) {
- var1.setColor(Color.lightGray);
- var1.drawLine(var3, var3, this.width - var3, var3);
- var1.drawLine(var3, var3, var3, this.height - var3);
- var1.setColor(Color.darkGray);
- var1.drawLine(this.width - var3, var3, this.width - var3, this.height - var3);
- var1.drawLine(var3, this.height - var3, this.width - var3, this.height - var3);
- }
-
- } else if (!this.isdown) {
- var1.drawImage(this.button_faded, 0, 0, this);
- } else {
- var1.drawImage(this.button_down, 1, 1, this);
-
- for(int var2 = 0; var2 < this.border; ++var2) {
- var1.setColor(Color.darkGray);
- var1.drawLine(var2, var2, this.width - var2, var2);
- var1.drawLine(var2, var2, var2, this.height - var2);
- var1.setColor(Color.lightGray);
- var1.drawLine(this.width - var2, var2, this.width - var2, this.height - var2);
- var1.drawLine(var2, this.height - var2, this.width - var2, this.height - var2);
- }
-
- }
- }
-
- public boolean mouseUp(Event var1, int var2, int var3) {
- this.isdown = false;
- this.isup = true;
- ((Component)this).repaint();
- if (this.url != "") {
- try {
- URL var4 = new URL(((Applet)this).getCodeBase(), this.url);
- ((Applet)this).getAppletContext().showDocument(var4, this.target);
- return true;
- } catch (Exception var5) {
- }
- }
-
- return true;
- }
-
- public void update(Graphics var1) {
- this.paint(var1);
- }
-
- public void start() {
- this.workThread = new Thread(this);
- this.workThread.start();
- }
-
- public String getAppletInfo() {
- return "ImageButton ver 1.3 by Sumit Birla\n" + "http://www.csee.usf.edu/~birla\n\n";
- }
-
- public boolean mouseDown(Event var1, int var2, int var3) {
- this.isup = false;
- this.isdown = true;
-
- try {
- this.sound.play();
- } catch (Exception var4) {
- ((Applet)this).showStatus("Error playing sound");
- }
-
- ((Component)this).repaint();
- return true;
- }
-
- public String getParameter(String var1, String var2) {
- String var3 = ((Applet)this).getParameter(var1);
- return var3 == null ? var2 : var3;
- }
-
- public void run() {
- do {
- ((Component)this).repaint();
-
- try {
- Thread.sleep(200L);
- } catch (InterruptedException var1) {
- }
- } while(this.animate);
-
- }
-
- public void init() {
- this.isup = false;
- this.isdown = false;
- ((Applet)this).showStatus("Loading ImageButton ver 1.3 by Sumit Birla...");
- this.tracker = new MediaTracker(this);
- String var1 = ((Applet)this).getParameter("button_up");
- this.button_up = ((Applet)this).getImage(((Applet)this).getCodeBase(), var1);
- this.tracker.addImage(this.button_up, 0);
- String var2 = this.getParameter("button_down", var1);
- if (var2.equals(var1)) {
- this.button_down = this.button_up;
- } else {
- this.button_down = ((Applet)this).getImage(((Applet)this).getCodeBase(), var2);
- this.tracker.addImage(this.button_down, 1);
- }
-
- try {
- this.tracker.waitForAll();
- } catch (InterruptedException var6) {
- ((Applet)this).showStatus("Loading interrupted");
- }
-
- var1 = this.getParameter("grayImage", "false");
- if (var1.equals("true")) {
- GrayFilter var3 = new GrayFilter();
- ImageProducer var4 = this.button_up.getSource();
- FilteredImageSource var5 = new FilteredImageSource(var4, var3);
- this.button_faded = ((Component)this).createImage(var5);
- } else {
- this.button_faded = this.button_up;
- }
-
- this.url = new String(this.getParameter("url", ""));
- this.status = new String(this.getParameter("status", ""));
- this.target = new String(this.getParameter("target", "_self"));
- var1 = this.getParameter("click_sound", "");
- this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), var1);
- var1 = this.getParameter("border", "1");
- Integer var11 = new Integer(var1);
- this.border = var11;
- var1 = this.getParameter("animate", "false");
- if (var1.equals("true")) {
- this.animate = true;
- }
-
- this.width = this.button_up.getWidth(this) - 1;
- this.height = this.button_up.getHeight(this) - 1;
- }
- }
-